package cn.hxzy.student.mapper;

import cn.hxzy.common.domain.TaskManager;
import cn.hxzy.common.domain.UserClass;
import cn.hxzy.common.domain.vo.TaskManagerVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TaskManagerMapper extends BaseMapper<TaskManager> {


    @Select("SELECT t1.*,t2.`nick_name`,t3.`task_name`,t3.`task_info`\n" +
            " FROM `task_manager` t1 \n" +
            " INNER JOIN sys_user t2 \n" +
            " ON t1.`student_id`=t2.`user_id`  \n" +
            " INNER JOIN sys_task t3\n" +
            " ON t1.`task_id`=t3.`task_id`\n" +
            " WHERE t1.teacher_id=#{teacherId}\n"+
            " ORDER BY   \n" +
            "    t1.submit_time DESC;")
    List<TaskManagerVo> GetTaskManagerList(Integer teacherId);

    //添加批复学生列表信息
    @Select("")
    List<TaskManagerVo> GetTaskManagerStudentList(Integer teacherId);


    @Select("SELECT t1.*,t2.`nick_name`,t3.`task_name`,t3.`task_info`,t4.*\n" +
            " FROM `task_manager` t1 \n" +
            " INNER JOIN sys_user t2 \n" +
            " ON t1.`student_id`=t2.`user_id`  \n" +
            " INNER JOIN sys_task t3\n" +
            " ON t1.`task_id`=t3.`task_id` \n" +
            " INNER JOIN sys_user_class t4 \n" +
            " ON t1.`student_id`=t4.`user_id` " +
            " WHERE t4.`class_id`=#{classId} AND t1.`teacher_id`=#{teacherId}\n"+
            " ORDER BY   \n" +
            "    t1.submit_time DESC;")
    List<TaskManagerVo> getClassIdByList(@Param("teacherId") Integer teacherId, @Param("classId") Integer classId);

    @Select("select submit_count from task_manager where student_id=#{userId} and task_id=#{taskId}")
    Integer countByStudentIdAndTaskId(@Param("userId") int userId, @Param("taskId") int taskId);

    @Update("UPDATE sys_user_class SET class_id = #{classId} WHERE user_id = #{userId}")
    Integer updateUserClass(@Param("userId") Integer userId, @Param("classId") Integer classId);



}
